class CulturesController < ApplicationController
  before_filter :login_required, :except => [:show]
  
  def authorized?(user = current_player())
    return user.admin?
  end
  
  # GET /cultures
  # GET /cultures.xml
  def index
    @cultures = Culture.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @cultures }
    end
  end

  # GET /cultures/1
  # GET /cultures/1.xml
  def show
    @culture = Culture.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @culture }
    end
  end

  # GET /cultures/new
  # GET /cultures/new.xml
  def new
    @culture = Culture.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @culture }
    end
  end

  # GET /cultures/1/edit
  def edit
    @culture = Culture.find(params[:id])
  end

  # POST /cultures
  # POST /cultures.xml
  def create
    @culture = Culture.new(params[:culture])

    respond_to do |format|
      if @culture.save
        flash[:notice] = 'Culture was successfully created.'
        format.html { redirect_to(@culture) }
        format.xml  { render :xml => @culture, :status => :created, :location => @culture }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @culture.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /cultures/1
  # PUT /cultures/1.xml
  def update
    @culture = Culture.find(params[:id])

    respond_to do |format|
      if @culture.update_attributes(params[:culture])
        flash[:notice] = 'Culture was successfully updated.'
        format.html { redirect_to(@culture) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @culture.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /cultures/1
  # DELETE /cultures/1.xml
  def destroy
    @culture = Culture.find(params[:id])
    @culture.destroy

    respond_to do |format|
      format.html { redirect_to(cultures_url) }
      format.xml  { head :ok }
    end
  end
end
